package cn.calm.swing.osgi.generator.service;

import javax.swing.ImageIcon;

import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;

import cn.calm.swing.osgi.api.DefaultWizardItemService;
import cn.calm.swing.osgi.api.entity.Project;
import cn.calm.swing.osgi.api.ui.IconDefaultMutableTreeNode;
import cn.calm.swing.osgi.generator.entity.GeneratorInfo;
import cn.calm.swing.osgi.generator.ui.Generator;

public class GeneratorWizardItemService extends DefaultWizardItemService {
	private IconDefaultMutableTreeNode node = new IconDefaultMutableTreeNode(
			"Generator");
	private BundleContext context;
	
	public GeneratorWizardItemService(BundleContext context) {
		this.context=context;
		node.setIcon(new ImageIcon(GeneratorWizardItemService.class
				.getResource("/icon.jpg")));
	}

	@Override
	public void action() {
		ServiceReference<Generator> serviceReference = context.getServiceReference(Generator.class);
		Generator service = context.getService(serviceReference);
		service.setProject(new Project());
		service.setGeneratorInfo(new GeneratorInfo());
		service.setVisible(true);
		context.ungetService(serviceReference);
	}

	@Override
	public IconDefaultMutableTreeNode getNode() {
		return node;
	}

}
